home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / Make / source / default.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-20  |  12.8 KB  |  496 lines

  1. /* Data base of default implicit rules for GNU Make.
  2. Copyright (C) 1988,89,90,91,92,93,94,95,96 Free Software Foundation, Inc.
  3. This file is part of GNU Make.
  4.  
  5. GNU Make is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. GNU Make is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with GNU Make; see the file COPYING.  If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "make.h"
  20. #include "rule.h"
  21. #include "dep.h"
  22. #include "filedef.h"
  23. #include "job.h"
  24. #include "commands.h"
  25. #include "variable.h"
  26.  
  27. /* Define GCC_IS_NATIVE if gcc is the native development environment on
  28.    your system (gcc/bison/flex vs cc/yacc/lex).  */
  29. #ifdef __MSDOS__
  30. #define GCC_IS_NATIVE
  31. #endif
  32.  
  33.  
  34. /* This is the default list of suffixes for suffix rules.
  35.    `.s' must come last, so that a `.o' file will be made from
  36.    a `.c' or `.p' or ... file rather than from a .s file.  */
  37.  
  38. static char default_suffixes[]
  39. #ifdef VMS
  40.   = ".exe .olb .ln .obj .c .cc .pas .p .for .f .r .y .l .mar \
  41. .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo \
  42. .w .ch .cweb .web .com .sh .elc .el";
  43. #else
  44.   = ".out .a .ln .o .c .cc .C .p .f .F .r .y .l .s .S \
  45. .mod .sym .def .h .info .dvi .tex .texinfo .texi .txinfo \
  46. .w .ch .web .sh .elc .el";
  47. #endif
  48.  
  49. static struct pspec default_pattern_rules[] =
  50.   {
  51.     { "(%)", "%",
  52.     "$(AR) $(ARFLAGS) $@ $<" },
  53.  
  54.     /* The X.out rules are only in BSD's default set because
  55.        BSD Make has no null-suffix rules, so `foo.out' and
  56.        `foo' are the same thing.  */
  57. #ifdef VMS
  58.     { "%.exe", "%",
  59.         "copy $< $@" },
  60. #else
  61.     { "%.out", "%",
  62.     "@rm -f $@ \n cp $< $@" },
  63. #endif
  64.     /* Syntax is "ctangle foo.w foo.ch foo.c".  */
  65.     { "%.c", "%.w %.ch",
  66.     "$(CTANGLE) $^ $@" },
  67.     { "%.tex", "%.w %.ch",
  68.     "$(CWEAVE) $^ $@" },
  69.  
  70.     { 0, 0, 0 }
  71.   };
  72.  
  73. static struct pspec default_terminal_rules[] =
  74.   {
  75. #ifdef VMS
  76.     /* RCS.  */
  77.     { "%", "%$$5lv", /* Multinet style */
  78.         "if f$$search($@) .nes. \"\" then +$(CHECKOUT,v)" },
  79.     { "%", "[.$$rcs]%$$5lv", /* Multinet style */
  80.         "if f$$search($@) .nes. \"\" then +$(CHECKOUT,v)" },
  81.     { "%", "%_v", /* Normal style */
  82.         "if f$$search($@) .nes. \"\" then +$(CHECKOUT,v)" },
  83.     { "%", "[.rcs]%_v", /* Normal style */
  84.         "if f$$search($@) .nes. \"\" then +$(CHECKOUT,v)" },
  85.  
  86.     /* SCCS.  */
  87.     /* ain't no SCCS on vms */
  88. #else
  89.     /* RCS.  */
  90.     { "%", "%,v",
  91.     "$(CHECKOUT,v)" },
  92.     { "%", "RCS/%,v",
  93.     "$(CHECKOUT,v)" },
  94.  
  95.     /* SCCS.  */
  96.     { "%", "s.%",
  97.     "$(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<" },
  98.     { "%", "SCCS/s.%",
  99.     "$(GET) $(GFLAGS) $(SCCS_OUTPUT_OPTION) $<" },
  100. #endif /* !VMS */
  101.     { 0, 0, 0 }
  102.   };
  103.  
  104. static char *default_suffix_rules[] =
  105.   {
  106. #ifdef VMS
  107.     ".obj.exe",
  108.     "$(LINK.obj) $^ $(LOADLIBES) $(LDLIBS) /exe=$@",
  109.     ".mar.exe",
  110.     "$(LINK.mar) $^ $(LOADLIBES) $(LDLIBS) /exe=$@",
  111.     ".c.exe",
  112.     "$(COMPILE.c) $^ \n $(LINK.obj) $(subst .c,.obj,$^) $(LOADLIBES) $(LDLIBS) /exe=$@",
  113.     ".cc.exe",
  114.     "$(COMPILE.cc) $^ \n $(LINK.obj) $(subst .cc,.obj,$^) $(LOADLIBES) $(LDLIBS) /exe=$@",
  115.     ".for.exe",
  116.     "$(COMPILE.for) $^ \n $(LINK.obj) $(subst .for,.obj,$^) $(LOADLIBES) $(LDLIBS) /exe=$@",
  117.     ".pas.exe",
  118.     "$(COMPILE.pas) $^ \n $(LINK.obj) $(subst .pas,.obj,$^) $(LOADLIBES) $(LDLIBS) /exe=$@",
  119.  
  120.     ".com",
  121.     "copy $< >$@",
  122.  
  123.     ".mar.obj",
  124.     "$(COMPILE.mar) /obj=$@ $<",
  125.     ".c.obj",
  126.     "$(COMPILE.c) /obj=$@ $<",
  127.     ".cc.obj",
  128.     "$(COMPILE.cc) /obj=$@ $<",
  129.     ".for.obj",
  130.     "$(COMPILE.for) /obj=$@ $<",
  131.     ".pas.obj",
  132.     "$(COMPILE.pas) /obj=$@ $<",
  133.  
  134.     ".y.c",
  135.     "$(YACC.y) $< \n rename y_tab.c $@",
  136.     ".l.c",
  137.     "$(LEX.l) $< \n rename lexyy.c $@",
  138.  
  139.     ".texinfo.info",
  140.     "$(MAKEINFO) $<",
  141.  
  142.     ".tex.dvi",
  143.     "$(TEX) $<",
  144.  
  145. #else /* ! VMS */
  146.  
  147.     ".o",
  148.     "$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  149.     ".s",
  150.     "$(LINK.s) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  151.     ".S",
  152.     "$(LINK.S) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  153.     ".c",
  154.     "$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  155.     ".cc",
  156.     "$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  157.     ".C",
  158.     "$(LINK.C) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  159.     ".f",
  160.     "$(LINK.f) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  161.     ".p",
  162.     "$(LINK.p) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  163.     ".F",
  164.     "$(LINK.F) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  165.     ".r",
  166.     "$(LINK.r) $^ $(LOADLIBES) $(LDLIBS) -o $@",
  167.     ".mod",
  168.     "$(COMPILE.mod) -o $@ -e $@ $^",
  169.  
  170.     ".def.sym",
  171.     "$(COMPILE.def) -o $@ $<",
  172.  
  173.     ".sh",
  174.     "cat $< >$@ \n chmod a+x $@",
  175.  
  176.     ".s.o",
  177.     "$(COMPILE.s) -o $@ $<",
  178.     ".S.o",
  179.     "$(COMPILE.S) -o $@ $<",
  180.     ".c.o",
  181.     "$(COMPILE.c) $< $(OUTPUT_OPTION)",
  182.     ".cc.o",
  183.     "$(COMPILE.cc) $< $(OUTPUT_OPTION)",
  184.     ".C.o",
  185.     "$(COMPILE.C) $< $(OUTPUT_OPTION)",
  186.     ".f.o",
  187.     "$(COMPILE.f) $< $(OUTPUT_OPTION)",
  188.     ".p.o",
  189.     "$(COMPILE.p) $< $(OUTPUT_OPTION)",
  190.     ".F.o",
  191.     "$(COMPILE.F) $< $(OUTPUT_OPTION)",
  192.     ".r.o",
  193.     "$(COMPILE.r) $< $(OUTPUT_OPTION)",
  194.     ".mod.o",
  195.     "$(COMPILE.mod) -o $@ $<",
  196.  
  197.     ".c.ln",
  198.     "$(LINT.c) -C$* $<",
  199.     ".y.ln",
  200. #ifndef __MSDOS__
  201.     "$(YACC.y) $< \n $(LINT.c) -C$* y.tab.c \n $(RM) y.tab.c",
  202. #else
  203.     "$(YACC.y) $< \n $(LINT.c) -C$* y_tab.c \n $(RM) y_tab.c",
  204. #endif
  205.     ".l.ln",
  206.     "@$(RM) $*.c\n $(LEX.l) $< > $*.c\n$(LINT.c) -i $*.c -o $@\n $(RM) $*.c",
  207.  
  208.     ".y.c",
  209. #ifndef __MSDOS__
  210.     "$(YACC.y) $< \n mv -f y.tab.c $@",
  211. #else
  212.     "$(YACC.y) $< \n mv -f y_tab.c $@",
  213. #endif
  214.     ".l.c",
  215.     "@$(RM) $@ \n $(LEX.l) $< > $@",
  216.  
  217.     ".F.f",
  218.     "$(PREPROCESS.F) $< $(OUTPUT_OPTION)",
  219.     ".r.f",
  220.     "$(PREPROCESS.r) $< $(OUTPUT_OPTION)",
  221.  
  222.     /* This might actually make lex.yy.c if there's no %R%
  223.        directive in $*.l, but in that case why were you
  224.        trying to make $*.r anyway?  */
  225.     ".l.r",
  226.     "$(LEX.l) $< > $@ \n mv -f lex.yy.r $@",
  227.  
  228.     ".S.s",
  229.     "$(PREPROCESS.S) $< > $@",
  230.  
  231.     ".texinfo.info",
  232.     "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@",
  233.  
  234.     ".texi.info",
  235.     "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@",
  236.  
  237.     ".txinfo.info",
  238.     "$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@",
  239.  
  240.     ".tex.dvi",
  241.     "$(TEX) $<",
  242.  
  243.     ".texinfo.dvi",
  244.     "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<",
  245.  
  246.     ".texi.dvi",
  247.     "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<",
  248.  
  249.     ".txinfo.dvi",
  250.     "$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<",
  251.  
  252.     ".w.c",
  253.     "$(CTANGLE) $< - $@",    /* The `-' says there is no `.ch' file.  */
  254.  
  255.     ".web.p",
  256.     "$(TANGLE) $<",
  257.  
  258.     ".w.tex",
  259.     "$(CWEAVE) $< - $@",    /* The `-' says there is no `.ch' file.  */
  260.  
  261.     ".web.tex",
  262.     "$(WEAVE) $<",
  263.  
  264. #endif /* !VMS */
  265.  
  266.     0, 0,
  267.   };
  268.  
  269. static char *default_variables[] =
  270.   {
  271. #ifdef VMS
  272.     "AR", "library/obj",
  273.     "ARFLAGS", "/replace",
  274.     "AS", "macro",
  275.     "CC", "cc",
  276.     "C++", "gcc/plus",
  277.     "CXX", "gcc/plus",
  278.     "CO", "co",
  279.     "CPP", "$(CC) /preprocess_only",
  280.     "FC", "fortran",
  281.     /* System V uses these, so explicit rules using them should work.
  282.        However, there is no way to make implicit rules use them and FC.  */
  283.     "F77", "$(FC)",
  284.     "F77FLAGS", "$(FFLAGS)",
  285.     "LD", "link",
  286.     "LEX", "lex",
  287.     "PC", "pascal",
  288.     "YACC", "yacc",    /* Or "bison -y"  */
  289.     "MAKEINFO", "makeinfo",
  290.     "TEX", "tex",
  291.     "TEXINDEX", "texindex",
  292.  
  293.     "RM", "delete/nolog",
  294.  
  295.     "LINK.obj", "$(LD) $(LDFLAGS)",
  296.     "COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
  297.     "COMPILE.cc", "$(C++) $(C++FLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  298.     "YACC.y", "$(YACC) $(YFLAGS)",
  299.     "LEX.l", "$(LEX) $(LFLAGS)",
  300.     "COMPILE.for", "$(FC) $(FFLAGS) $(TARGET_ARCH)",
  301.     "COMPILE.pas", "$(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
  302.     "COMPILE.mar", "$(AS) $(ASFLAGS) $(TARGET_MACH)",
  303.     "LINT.c", "$(LINT) $(LINTFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
  304.  
  305.     "MV", "rename/new_version",
  306.     "CP", "copy",
  307.  
  308. #else /* !VMS */
  309.  
  310.     "AR", "ar",
  311.     "ARFLAGS", "rv",
  312.     "AS", "as",
  313. #ifdef GCC_IS_NATIVE
  314.     "CC", "gcc",
  315.     "CXX", "gcc",
  316. #else
  317.     "CC", "cc",
  318.     "CXX", "g++",
  319. #endif
  320.  
  321.     /* This expands to $(CO) $(COFLAGS) $< $@ if $@ does not exist,
  322.        and to the empty string if $@ does exist.  */
  323.     "CHECKOUT,v",
  324.     "+$(patsubst $@-noexist,$(CO) $(COFLAGS) $< $@,\
  325.          $(filter-out $@,$(firstword $(wildcard $@) $@-noexist)))",
  326.  
  327.     "CO", "co",
  328.     "CPP", "$(CC) -E",
  329. #ifdef    CRAY
  330.     "CF77PPFLAGS", "-P",
  331.     "CF77PP", "/lib/cpp",
  332.     "CFT", "cft77",
  333.     "CF", "cf77",
  334.     "FC", "$(CF)",
  335. #else    /* Not CRAY.  */
  336. #ifdef    _IBMR2
  337.     "FC", "xlf",
  338. #else
  339. #ifdef    __convex__
  340.     "FC", "fc",
  341. #else
  342.     "FC", "f77",
  343. #endif /* __convex__ */
  344. #endif /* _IBMR2 */
  345.     /* System V uses these, so explicit rules using them should work.
  346.        However, there is no way to make implicit rules use them and FC.  */
  347.     "F77", "$(FC)",
  348.     "F77FLAGS", "$(FFLAGS)",
  349. #endif    /* Cray.  */
  350.     "GET", SCCS_GET,
  351.     "LD", "ld",
  352. #ifdef GCC_IS_NATIVE
  353.     "LEX", "flex",
  354. #else
  355.     "LEX", "lex",
  356. #endif
  357.     "LINT", "lint",
  358.     "M2C", "m2c",
  359. #ifdef    pyr
  360.     "PC", "pascal",
  361. #else
  362. #ifdef    CRAY
  363.     "PC", "PASCAL",
  364.     "SEGLDR", "segldr",
  365. #else
  366.     "PC", "pc",
  367. #endif    /* CRAY.  */
  368. #endif    /* pyr.  */
  369. #ifdef GCC_IS_NATIVE
  370.     "YACC", "bison -y",
  371. #else
  372.     "YACC", "yacc",    /* Or "bison -y"  */
  373. #endif
  374.     "MAKEINFO", "makeinfo",
  375.     "TEX", "tex",
  376.     "TEXI2DVI", "texi2dvi",
  377.     "WEAVE", "weave",
  378.     "CWEAVE", "cweave",
  379.     "TANGLE", "tangle",
  380.     "CTANGLE", "ctangle",
  381.  
  382.     "RM", "rm -f",
  383.  
  384.     "LINK.o", "$(CC) $(LDFLAGS) $(TARGET_ARCH)",
  385.     "COMPILE.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  386.     "LINK.c", "$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  387.     "COMPILE.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  388.     "COMPILE.C", "$(COMPILE.cc)",
  389.     "LINK.cc", "$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  390.     "LINK.C", "$(LINK.cc)",
  391.     "YACC.y", "$(YACC) $(YFLAGS)",
  392.     "LEX.l", "$(LEX) $(LFLAGS) -t",
  393.     "COMPILE.f", "$(FC) $(FFLAGS) $(TARGET_ARCH) -c",
  394.     "LINK.f", "$(FC) $(FFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  395.     "COMPILE.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  396.     "LINK.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  397.     "COMPILE.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -c",
  398.     "LINK.r", "$(FC) $(FFLAGS) $(RFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  399.     "COMPILE.def", "$(M2C) $(M2FLAGS) $(DEFFLAGS) $(TARGET_ARCH)",
  400.     "COMPILE.mod", "$(M2C) $(M2FLAGS) $(MODFLAGS) $(TARGET_ARCH)",
  401.     "COMPILE.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c",
  402.     "LINK.p", "$(PC) $(PFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)",
  403.     "LINK.s", "$(CC) $(ASFLAGS) $(LDFLAGS) $(TARGET_MACH)",
  404.     "COMPILE.s", "$(AS) $(ASFLAGS) $(TARGET_MACH)",
  405.     "LINK.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_MACH)",
  406.     "COMPILE.S", "$(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_MACH) -c",
  407.     "PREPROCESS.S", "$(CC) -E $(CPPFLAGS)",
  408.     "PREPROCESS.F", "$(FC) $(FFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -F",
  409.     "PREPROCESS.r", "$(FC) $(FFLAGS) $(RFLAGS) $(TARGET_ARCH) -F",
  410.     "LINT.c", "$(LINT) $(LINTFLAGS) $(CPPFLAGS) $(TARGET_ARCH)",
  411.  
  412. #ifndef    NO_MINUS_C_MINUS_O
  413.     "OUTPUT_OPTION", "-o $@",
  414. #endif
  415.  
  416. #ifdef    SCCS_GET_MINUS_G
  417.     "SCCS_OUTPUT_OPTION", "-G$@",
  418. #endif
  419.  
  420. #endif /* !VMS */
  421.     0, 0
  422.   };
  423.  
  424. /* Set up the default .SUFFIXES list.  */
  425.  
  426. void
  427. set_default_suffixes ()
  428. {
  429.   suffix_file = enter_file (".SUFFIXES");
  430.  
  431.   if (no_builtin_rules_flag)
  432.     (void) define_variable ("SUFFIXES", 8, "", o_default, 0);
  433.   else
  434.     {
  435.       char *p = default_suffixes;
  436.       suffix_file->deps = (struct dep *)
  437.     multi_glob (parse_file_seq (&p, '\0', sizeof (struct dep), 1),
  438.             sizeof (struct dep));
  439.       (void) define_variable ("SUFFIXES", 8, default_suffixes, o_default, 0);
  440.     }
  441. }
  442.  
  443. /* Enter the default suffix rules as file rules.  This used to be done in
  444.    install_default_implicit_rules, but that loses because we want the
  445.    suffix rules installed before reading makefiles, and thee pattern rules
  446.    installed after.  */
  447.  
  448. void
  449. install_default_suffix_rules ()
  450. {
  451.   register char **s;
  452.  
  453.   if (no_builtin_rules_flag)
  454.     return;
  455.  
  456.  for (s = default_suffix_rules; *s != 0; s += 2)
  457.     {
  458.       register struct file *f = enter_file (s[0]);
  459.       /* Don't clobber cmds given in a makefile if there were any.  */
  460.       if (f->cmds == 0)
  461.     {
  462.       f->cmds = (struct commands *) xmalloc (sizeof (struct commands));
  463.       f->cmds->filename = 0;
  464.       f->cmds->commands = s[1];
  465.       f->cmds->command_lines = 0;
  466.     }
  467.     }
  468. }
  469.  
  470.  
  471. /* Install the default pattern rules.  */
  472.  
  473. void
  474. install_default_implicit_rules ()
  475. {
  476.   register struct pspec *p;
  477.  
  478.   if (no_builtin_rules_flag)
  479.     return;
  480.  
  481.   for (p = default_pattern_rules; p->target != 0; ++p)
  482.     install_pattern_rule (p, 0);
  483.  
  484.   for (p = default_terminal_rules; p->target != 0; ++p)
  485.     install_pattern_rule (p, 1);
  486. }
  487.  
  488. void
  489. define_default_variables ()
  490. {
  491.   register char **s;
  492.  
  493.   for (s = default_variables; *s != 0; s += 2)
  494.     (void) define_variable (s[0], strlen (s[0]), s[1], o_default, 1);
  495. }
  496.